package com.review.backpack_01;

import java.util.Arrays;

public class BP10 {
    public static int coinChange(int[] coins, int amount) {
        // 用最少的物品恰好填满背包（默认物体大小和物体价值一致）
        // 类似完全背包，只不过记录个数
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, amount + 1);
        dp[0] = 0;
        for (int i = 0; i < coins.length; i++) {
            for (int j = coins[i]; j <= amount; j++) {
                dp[j] = Math.min(dp[j], dp[j - coins[i]] + 1);
            }
        }
        return dp[amount] == (amount + 1) ? -1 : dp[amount];
    }

    public static void main(String[] args) {
        System.out.println(coinChange(new int[]{1, 2, 5}, 11));
/*        int[] ints = {1, 2, 3, 5, 6, 7};
        for (int i : Arrays.copyOfRange(ints, 0, 3)) {
            System.out.print(i + ",");
        }*/
    }
}
